<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>onmessage</title>
</head>
<body>
<div>
    <h2>target.html,以下是接收到的消息：</h2>
         <p id="msg"></p>
     </div>
    <script>
        window.onload = function() {
            if(window.addEventListener){
                window.addEventListener("message", handleMessage, false);
            }
            else{
                window.attachEvent("onmessage", handleMessage);
            }

            function handleMessage(event) {
                event = event || window.event;
                
                    document.getElementById('msg').innerHTML = event.data;
                
            }
        }
    </script>
</body>
</html>